package com.hrms.common.utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class ListConverter {

    /**
     * Converts a List of unknown type to a List of a specific type.
     *
     *  sourceList The source list of unknown type.
     *  targetClass The target class to which the elements should be cast.
     * @param <T> The type parameter for the target class.
     * @return A new List containing elements of the specified type.
     */
    public static <T> List<T> castList(Object obj, Class<T> clazz) {
        List<T> result = new ArrayList<>();
        if (obj instanceof List<?>) {
            for (Object o : (List<?>) obj) {
                result.add(clazz.cast(o));
            }
            return result;
        }
        return null;
    }
}